package com.eatme.web.security.authentication.wechat.applet.authentication;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

public class WechatAppletAuthenticationToken extends AbstractAuthenticationToken {


    /**
     * 这里的 principal 指的是 code （未认证的时候）
     */
    private final Object principal;

    private String session_key;


    public WechatAppletAuthenticationToken(Object principal, String session_key) {
        super((Collection)null);
        this.principal = principal;
        this.session_key = session_key;
        this.setAuthenticated(false);
    }

    public WechatAppletAuthenticationToken(Object principal, String session_key,Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.session_key = session_key;
        this.setAuthenticated(false);
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        if (isAuthenticated) {
            throw new IllegalArgumentException("Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
        } else {
            super.setAuthenticated(false);
        }
    }

    public String getSession_key() {
        return session_key;
    }

    public void setSession_key(String session_key) {
        this.session_key = session_key;
    }
}